global data ../china/data

set more off


use $data/imp2005china, clear
append using $data/imp2006china

drop if rel==1
gen city=substr(manuf_id,-3,3)

/* Assigns 3-letter cities to individual provinces */
include $do/provinces.do 
provinces
drop if province==""

gen p=v/q
gen log_price=log(p)

gen hs4=substr(hs,1,4)
merge m:1 hs manuf_id year using $quality/quality_est_final, keepusing(lambda)
drop if _m==2

save $data/all0506_hs10, replace


use $data/all0506_hs10, clear

egen min_year=min(year)
drop if year!=min_year

bysort hs: egen tot_v=total(v)
egen tot_tot_v=total(v)
gen hs_share=tot_v/tot_tot_v

egen exporter_tag=tag(manuf_id hs)
egen importer_tag=tag(firmid hs)

bysort hs: egen exporters=total(exporter_tag)
bysort hs: egen importers=total(importer_tag)

egen hs_tag=tag(hs)

drop if hs_tag!=1

gsort -hs_share
list hs hs_share exporters importers in 1/100


/* Top 50
hs
8471300000 8521900000 8525209070 8520900080 6403999065 8528215501 9405106010 6204699044 8471606400 8471500085
7321116000 8471604580 6307909889 8414513000 6402991865 9405408000 8517110000 6403996040 9503700000 6403996075
9401790005 7326908587 8525404000 9401616010 8528127201 4203104060 9403509040 4202923031 9401614010 4011201015
9404908522 6110901060 6403999031 8471801000 8467210010 6110909090 6403919045 3925301000 6303922010 6204624020
8708704545 6206100040 6403916040 8519990045 8415103040 9405406000 6402999030 8472909080 6403916075 6110303055

Too small? #3, #6, #9 */

/* Original List
local hs10list 8521900000 8525209070 8520900080 8471500085 9405106010 7321116000 8528215501 8414513000 ///
8471604580 6403996040 9401790005 8525404000 8471801000 6403999031 4011201015 8708704545 8467210010 6403916040 ///
3925301000 8528127201 8415103040 6402999030 8472909080 8519990045 8467220070 6402999060 8414519090 7202700000 ///
3926201010 8509100080 6302319020 6110121060 9401308030 8516290030 8712003500 8516500090 8539310060 8708395030 ///
6111206010 8527136040 8527316040 3926201020 8418210010 3913902000 8516710020 6402991815 4412140540 9401790015 ///
6306229030 8471704065 */

use $data/all0506_hs10, clear

local hs10list 8521900000 8525209070 8520900080 8471500085 9405106010 7321116000 8528215501 8414513000 ///
8471604580 6403996040 9401790005 8525404000 8471801000 6403999031 4011201015 8708704545 8467210010 6403916040 ///
3925301000 8528127201 8415103040 6402999030 8472909080 8519990045 8467220070 6402999060 8414519090 7202700000 ///
3926201010 8509100080 6302319020 6110121060 9401308030 8516290030 8712003500 8516500090 8539310060 8708395030 ///
6111206010 8527136040 8527316040 3926201020 8418210010 3913902000 8516710020 6402991815 4412140540 9401790015 ///
6306229030 8471704065 8471300000 6403999065 6204699044 6307909889 6402991865 9405408000

gen samp=0 
local i=0

foreach num of local hs10list {

local i=`i'+1
disp `i'
replace samp=`i' if hs=="`num'"

}

drop if samp==0
sort samp
duplicates drop hs, force
outfile hs using $data/hs10_indlist.raw, replace
